package com.michir.project.tests.jms;

import javax.annotation.Resource;
import javax.ejb.MessageDriven;
import javax.ejb.SessionContext;
import javax.jms.JMSException;
import javax.jms.Message;
import javax.jms.MessageListener;
import javax.jms.ObjectMessage;

@MessageDriven
public class MyMdb implements MessageListener {

	@Resource
	private SessionContext context;
	
	@Override
	public void onMessage(Message arg0) {
		if (! (arg0 instanceof ObjectMessage)) {
			context.setRollbackOnly();
			return;
		}
		ObjectMessage message = (ObjectMessage) arg0;
		try {
			Person person = (Person) message.getObject();
			person.setReadState(Boolean.TRUE);
		} catch (JMSException e) {
			e.printStackTrace();
			context.setRollbackOnly();
		}
	}
}
